package ide.ccf.ccproject.editors;

import org.eclipse.jface.text.rules.ICharacterScanner;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.rules.WordRule;
import org.eclipse.jface.text.rules.IWordDetector;

/**
 * 函数规则
 * 与WordRule基本相同，不同之处在于会检测匹配单词后面是否有字符'('
 *
 */
public class FunctionRule extends WordRule 
{
	/**
	 * 构造器
	 * @param detector
	 * @param defaultToken
	 */
	public FunctionRule(IWordDetector detector, IToken defaultToken) 
	{
		super(detector, defaultToken);
	}
	
	/**
	 * 
	 */
	public IToken evaluate(ICharacterScanner scanner) 
	{
		IToken token = super.evaluate(scanner);
		
		if (!token.isUndefined()) 
		{
    	    int c = scanner.read();
    	    
    	    // 不要高亮最后一个字符，只是为了检测
		    scanner.unread();
		    
	  	    if (c == '(') 
	  	    {
			    return token;
		    }
		    unreadBuffer(scanner);
		}
		return Token.UNDEFINED;
	}
}